<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
    <composite:attribute name="workflowBean" required="true"/>
</composite:interface>

<composite:implementation>
    <div class="workflow-topbar clearfix"
         style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
        <p:toolbar>
            <f:facet name="right">
                <p:commandButton value="保存" icon="fa fa-save"
                                 update="@form" actionListener="#{cc.attrs.workflowBean.onSave}"/>
                <p:commandButton value="审批" icon="fa fa-rss"
                                 actionListener="#{cc.attrs.workflowBean.onPrepareCommitAndShowNextActivityInfoDialog}"
                                 update="workflowApproveDialog"
                                 rendered="#{cc.attrs.workflowBean.nextActivitiesWithoutEndEvent.size() > 0}"/>
                <p:commandButton value="同意" icon="fa fa-check"
                                 action="#{cc.attrs.workflowBean.onPass}"
                                 ajax="true" rendered="#{cc.attrs.workflowBean.passEnd}"/>
                <p:commandButton value="拒绝" icon="fa fa-remove"
                                 action="#{cc.attrs.workflowBean.onReject}"
                                 ajax="false" rendered="false"/>
                <p:commandButton value="作废" icon="fa fa-trash"
                                 action="#{cc.attrs.workflowBean.onCancel}"
                                 rendered="#{cc.attrs.workflowBean.cancelEnd}">
                    <p:confirm header="提示信息" message="是否确定作废该流程?"
                               icon="ui-icon-alert"/>
                </p:commandButton>
                <p:commandButton value="回退" icon="fa fa-backward"
                                 update="workflowBackDialog"
                                 oncomplete="PF('workflowBackDialogWidgetVar').show();"
                                 rendered="false"/>
                <!--rendered="#{cc.attrs.workflowBean.rejectEnd}"-->
                <!--rendered="#{cc.attrs.workflowBean.lastTask != null}-->
                <!--<p:commandButton value="转办" icon="fa fa-retweet"-->
                <!--update="@form"/>-->
                <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"/>
            </f:facet>
        </p:toolbar>
    </div>
    <div class="ui-g-12"><h3><b>审批意见</b></h3></div>
    <div class="ui-g-2">
        <p:outputLabel value="审批意见"/>
    </div>
    <div class="ui-g-10">
        <p:inputTextarea value="#{cc.attrs.workflowBean.opinion.opinion}" rows="10"/>
    </div>
    <div class="ui-g-2">
        <p:outputLabel value="审批备注"/>
    </div>
    <div class="ui-g-10">
        <p:inputTextarea value="#{cc.attrs.workflowBean.opinion.remark}" rows="10"/>
    </div>

    <div class="ui-g-12"><h3><b>审批历史</b></h3></div>
    <p:dataTable
            style="width: 100%"
            var="opinion"
            value="#{cc.attrs.workflowBean.opinions}"
            emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
            reflow="true"
            resizableColumns="true">

        <p:column headerText="审批节点">
            <h:outputText value="#{opinion.taskName}"/>
        </p:column>
        <p:column headerText="审批结果">
            <h:outputText value="#{opinion.operateType.label}"/>
        </p:column>
        <p:column headerText="审批人角色">
            <h:outputText value="#{opinion.roleName}"/>
        </p:column>
        <p:column headerText="审批人">
            <h:outputText value="#{opinion.userName}"/>
        </p:column>
        <p:column headerText="审批意见">
            <h:outputText value="#{opinion.opinion}"/>
        </p:column>
        <p:column headerText="审批备注">
            <h:outputText value="#{opinion.remark}"/>
        </p:column>
        <p:column headerText="审批时间">
            <h:outputText value="#{opinion.createTime}">
                <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
            </h:outputText>
        </p:column>
    </p:dataTable>
    <p:dialog id="workflowApproveDialog" widgetVar="workflowApproveDialogWidgetVar" modal="true" header="流程审批"
              resizable="false" width="600" height="400">
        <p:toolbar>
            <f:facet name="right">
                <p:commandButton value="提交" icon="fa fa-check" action="#{cc.attrs.workflowBean.onApprove}"
                                 ajax="false"/>
            </f:facet>
        </p:toolbar>
        <div class="ui-g ui-fluid" style="padding-top: 30px;">
            <div class="ui-g-12 ">
                <div class="ui-g-12 card">
                    <div class="ui-g-3">当前环节</div>
                    <div class="ui-g-9">
                        <h:outputText value="#{cc.attrs.workflowBean.currentActivity.activityName}"/>
                    </div>
                    <div class="ui-g-3">后续环节</div>
                    <div class="ui-g-9">
                        <p:selectOneMenu value="#{cc.attrs.workflowBean.selectedNextActivityId}">
                            <f:selectItems
                                    value="#{cc.attrs.workflowBean.nextActivitiesWithoutEndEvent}"
                                    var="activity"
                                    itemLabel="#{activity.activityName}" itemValue="#{activity.id}"/>
                        </p:selectOneMenu>
                    </div>
                    <div class="ui-g-3">后续处理人</div>
                    <div class="ui-g-9">
                        <p:selectOneMenu value="#{cc.attrs.workflowBean.selectedNextAssignee}">
                            <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                            <f:selectItems
                                    value="#{cc.attrs.workflowBean.nextAsigneeSystemUser}"
                                    var="user"
                                    itemLabel="#{user.name}" itemValue="#{user.account}"/>
                        </p:selectOneMenu>
                    </div>
                </div>
            </div>
        </div>
    </p:dialog>
    <p:dialog id="workflowBackDialog" widgetVar="workflowBackDialogWidgetVar" modal="true" header="流程回退"
              resizable="false" width="600" height="400">
        <p:toolbar>
            <f:facet name="right">
                <p:commandButton value="提交" icon="fa fa-check" action="#{cc.attrs.workflowBean.onBack}"
                                 ajax="false"/>
            </f:facet>
        </p:toolbar>
        <div class="ui-g ui-fluid" style="padding-top: 30px;">
            <div class="ui-g-12 ">
                <div class="ui-g-12 card">
                    <div class="ui-g-3">当前环节</div>
                    <div class="ui-g-9">
                        <h:outputText value="#{cc.attrs.workflowBean.currentActivity.activityName}"/>
                    </div>
                    <div class="ui-g-3">上一个环节</div>
                    <div class="ui-g-9">
                        <p:selectOneMenu>
                            <f:selectItem itemLabel="#{cc.attrs.workflowBean.lastTask.taskName}"
                                          itemValue="#{cc.attrs.workflowBean.lastTask.id}"/>
                        </p:selectOneMenu>
                    </div>
                    <div class="ui-g-3">上一个环节处理人</div>
                    <div class="ui-g-9">
                        <p:selectOneMenu>
                            <f:selectItem itemLabel="#{cc.attrs.workflowBean.lastTask.assigneeName}"
                                          itemValue="#{cc.attrs.workflowBean.lastTask.assignee}"/>
                        </p:selectOneMenu>
                    </div>
                </div>
            </div>
        </div>
    </p:dialog>
</composite:implementation>
</html>